package com.sicheng.蓝桥.练习题.dp.坐标型;

import java.util.Scanner;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/5/21 21:33
 */
@SuppressWarnings("all")
public class 质数行者 {
    /**
     * http://lx.lanqiao.cn/problem.page?gpid=T2882
     * <p>
     * 输入
     * 5 6 1
     * 3 4 1 1 2 1
     * <p>
     * 输出
     * 11
     * <p>
     * <p>
     * 输入
     * 30 40 50
     * 27 9 40 29 15 22
     * 输出:
     * 341649564
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int w = scanner.nextInt();
        int l = Math.max(w, Math.max(n, m));
        //障碍点1
        int x1 = scanner.nextInt();
        int y1 = scanner.nextInt();
        int z1 = scanner.nextInt();
        //障碍点2
        int x2 = scanner.nextInt();
        int y2 = scanner.nextInt();
        int z2 = scanner.nextInt();

        boolean[] notPrime = new boolean[l + 1];
        int[] prime = new int[l + 1];
        int count = 0;
        //欧拉筛筛出范围内所有质数
        for (int i = 2; i <= l; i++) {
            if (!notPrime[i]) {
                prime[count++] = i;
            }
            for (int j = 0; j < count && i * prime[j] <= l; j++) {
                notPrime[i * prime[j]] = true;
                if (i % prime[j] == 0)
                    break;
            }
        }


        //dp[i][j][k]代表到达(i,j,k)有多少种方案
        //当(i,j,k)不是障碍点时,有三个方向的质数集转移而来，
        // prime[p]表示一个质数  ====dp[i][j][k] += dp[i- prime[p]][j][k]+dp[i][j- prime[p]][k]+dp[i][j][k- prime[p]]

        // 当i==2||j==2是任意一个方向转移过来都是0所以直接break,
        // 当prime[p]大于i,j,k三个方向的最起始位置直接break======>i <= prime[p] && j <= prime[p] && k <= prime[p]
        // 举例说明想要达到(3,3,1) 质数是2就是极限了,(1,1,1)->(3,3,1)

        // 此题非常变态long会溢出,非常容易疏忽,所以要一边算一边取模
        long[][][] dp = new long[n + 1][m + 1][w + 1];
        dp[1][1][1] = 1;
        long mod = 1000000007;
        long a = 0, b = 0, c = 0;
        for (int k = 1; k <= w; k++) {
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    for (int p = 0; p < count; p++) {
                        // (i,j,k)不是障碍点就更新
                        if (isOK(x1, y1, z1, x2, y2, z2, k, i, j)) {
                            //此处可以提前break
                            if (i <= prime[p] && j <= prime[p] && k <= prime[p] || i == 2 || j == 2 || k == 2) {
                                break;
                            }
                            a = 0;
                            b = 0;
                            c = 0;
                            if (i > prime[p])
                                a = dp[i - prime[p]][j][k];
                            if (j > prime[p])
                                b = dp[i][j - prime[p]][k];
                            if (k > prime[p])
                                c = dp[i][j][k - prime[p]];
                            //错误解法 long会直接炸掉
                            //dp[i][j][k] += a + b + c;
                            dp[i][j][k] = (dp[i][j][k] + a + b + c) % mod;
                        }
                    }
                }
            }

        }

        System.out.println(dp[n][m][w]);
    }

    private static boolean isOK(int x1, int y1, int z1, int x2, int y2, int z2, int k, int i, int j) {
        return !((i == x1 && j == y1 && k == z1) || (i == x2 && j == y2 && k == z2));
    }
}
